/**
 * @param {string} s
 * @return {string}
 */
var reverseWords = function(s) {
    let result = []
    s = s.trim().split(' ')
    for (let i = s.length -1; i>=0; i--) {
        if (s[i] == '') {
            continue
        }
        result.push(s[i])
    }
    return result.join(' ')

};
var reverseWords = function(s) {
    let res = ''
    s = s.trim().split(' ')
    // return s
    for (let i = s.length -1; i>=0; i--) {
        if (s[i] == '') {
            continue
        }
        res += s[i]
        if (i != 0) {
            res += ' '
        }
    }
    return res
}
let s = "a good   example"
console.log(reverseWords(s))